﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Web;

namespace PeaceBlog
{
    public class CrypterHelper
    {
        private static string[] CrypteWords = { "|faacw213d123fd|", 
                                                  "-f932jd2aöxmma-", 
                                                  "?e02dk03kd23a?", 
                                                  "'adad23d23dmoa0'", 
                                                  "^adac92kk2e30e^", 
                                                  "%491m23d230dö%", 
                                                  "&03k2m3f0234&", 
                                                  "/mwofmw0rf32*/", 
                                                  "(9moköer0v45k0(", 
                                                  ")öo5075067n4ı9)" };

        public static string MD5Hash(string input)
        {
            using (MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider())
            {
                byte[] encoded = md5.ComputeHash(ASCIIEncoding.Default.GetBytes(input));
                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < encoded.Length; i++)
                    sb.Append(encoded[i].ToString("x2"));
                return sb.ToString();
            }
        }

        public static string PasswordHash(string sifre)
        {
            return MD5Hash(
                MD5Hash(CrypteWords[((sifre.Length <= 10) ? (sifre.Length - 1) : (sifre.Length / 3))]) +
                MD5Hash(sifre) +
                MD5Hash(CrypteWords[((sifre.Length <= 10) ? (sifre.Length - 1) : (sifre.Length / 3))])
                );
        }
    }
}